e = sel => document.getElementById(sel)

Array.prototype.indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};

Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

/*
var log = function(s) {
    e("id-text-log").value += '\n' + s
}
*/
var log = console.log.bind(console)

const config = {
    fps : 60,
    run_pic : 12,
    stop_pic : 6,
    jump_pic : 12,
    action_speed : 8,
    player_speed : 2,
    jump_hight : 2,
    gravity : 0.15,
}

var myUtils = {
    paused : false,
    clicked : false,
    bricks : [],
}

var randomBetween = function(min, max){
    return Math.floor(min + Math.random() * (max - min + 1))
}

var collide = function(a, b){
    xa1 = a.x
    ya1 = a.y
    xa2 = a.x + a.w
    ya2 = a.y + a.h
    xb1 = b.x
    yb1 = b.y 
    xb2 = b.x + b.w
    yb2 = b.y + b.h

    if (Math.min(xa2,xb2) >= Math.max(xa1,xb1)
        && Math.min(ya2,yb2) >= Math.max(ya1,yb1)){
            return true
        }
    return false
}

var DebugMode = function(game, enable){
    if (!enable){
        return
    }

    window.addEventListener("keydown", function(event){
        switch(event.code){
            case "Space": myUtils.paused = !myUtils.paused; break;
        }
    })
}

const kofFrame = {
    bg:{w:752,h:256,count:16,keys:"bg",},
    jump_forward:{w:149,h:196,count:17,keys:"KeyDKeyW",},
    run:{w:123,h:90,count:8,keys:"KeyDKeyD",},
    back:{w:70,h:107,count:9,keys:"back",},
    down:{w:65,h:64,count:6,keys:"down",},
    forward:{w:68,h:104,count:10,keys:"forward",},
    jump:{w:68,h:190,count:13,keys:"jump",},
    stand:{w:74,h:102,count:9,keys:"stand",},
}


/*
const kofFrame = {
    bg:{w:752,h:256,count:16,keys:"bg",},
    jump_forward:{w:149,h:196,count:17,keys:"KeyDKeyW",},
    run:{w:123,h:90,count:8,keys:"KeyDKeyD",},
    back:{w:70,h:107,count:9,keys:"KeyA",},
    down:{w:65,h:64,count:6,keys:"KeyS",},
    forward:{w:68,h:104,count:10,keys:"KeyD",},
    jump:{w:68,h:190,count:13,keys:"KeyW",},
    stand:{w:74,h:102,count:9,keys:"stand",},
}
*/